class ClusterBar {
  float clusterBarX1, clusterBarX2, clusterBarY1, clusterBarY2;
  float clusterBtnX1, clusterBtnX2, clusterBtnY1, clusterBtnY2;
  int cluster;
  float[] clusterAverage;
  
  ClusterBar(float X1, float X2, float Y1, float Y2) {
    clusterBarX1 = X1;
    clusterBarX2 = X2;
    clusterBarY1 = Y1;
    clusterBarY2 = Y2;
    clusterBtnX1 = clusterBarX1;
    clusterBtnX2 = clusterBarX1+3;
    clusterBtnY1 = clusterBarY1 - 5;
    clusterBtnY2 = clusterBarY2 + 5;
    
    cluster = 1;
  }
  
  void draw() {
    noStroke();
    fill(175);
    rectMode(CORNERS);
    
    //draw slider bar rect
    rect(clusterBarX1, clusterBarY1, clusterBarX2, clusterBarY2);
    stroke(240);
    fill(240);
    strokeWeight(1);
    textAlign(CENTER);
    textSize(8);
    float space = (clusterBarX2-clusterBarX1)/11;
    for (int i = 0; i < 12; i++) {
      line(clusterBarX1+i*space, clusterBarY2, clusterBarX1+i*space, clusterBarY2+4);
      text(i+1, clusterBarX1+i*space, clusterBarY2+14);
      if (cluster == i) {
        clusterBtnX1 = clusterBarX1+(i-1)*space;
        clusterBtnX2 = clusterBtnX1 + 3;
      }
    }
    textSize(10);
    text("Clustering of Months",clusterBarX1+(clusterBarX2-clusterBarX1)/2, clusterBarY2+25);
    
    fill(100);
    stroke(0);
    //draw slider
    rect(clusterBtnX1-3, clusterBtnY1, clusterBtnX2, clusterBtnY2);
    
  }//draw
  
  boolean mouseOver() {
    return (mouseX > clusterBtnX1 - 10 && mouseX < clusterBtnX2 + 10 && mouseY > clusterBtnY1 && mouseY < clusterBtnY2);
  }
  
  void mouseDragged() {
     if (mouseX < clusterBarX1)
       clusterBtnX1 = clusterBarX1; 
     else if (mouseX > clusterBarX2)
       clusterBtnX1 = clusterBarX2;
     else
       clusterBtnX1 = mouseX;
       
     clusterBtnX2 = clusterBtnX1 + 3;
     cluster = int(map(clusterBtnX1, clusterBarX1, clusterBarX2, 1, 12));
  }
  
  /*void calcClusterData() {
    int c = ceil(12.0/cluster);
    int yearsMin = years[0];
    clusterAverage = new float[rowCount];
    for (int r = 0; r < rowCount; r++)
        clusterAverage[r]= 0;
    int count = 0;
    for (int row = 0; row < rowCount;) {
        int monthNum = int(getMonth(row));
        int yearNum = years[row] - years[0];
        int s1 = floor(((monthNum)%12)/cluster);
        //println(yearNum + ", " + monthNum + ", " + season 
            //+ ", " + cluster + ", " + c);
        float average = 0;
        for (int m = 0; (m < cluster); m++) {
           if (row + m < data.getRowCount()) {
             if (years[row+m] - yearsMin != yearNum) {
               int s2 = floor((getMonth(row+m)%12)/cluster);
               if (s2 != s1)
                 break;
               else if (cluster == 12)
                 break;
             }
             average += data.getFloat(row+m, currentColumn);
             count++;
           } else 
             break;
        }
        average /= count;
        for (int i = 0; i < count; i++) {
          clusterAverage[row+i] = average;
        }
        
        row += count;
        count = 0;
    }
  }

  float getClusterData(int row) {
    return clusterAverage[row];
  }*/
}//class
